package cc.chengheng.repository;

import cc.chengheng.entity.Users;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;


@Repository
public class UsersRepository {

    @Resource
    private JdbcTemplate jdbcTemplate;

    public Users selectUsername(String username) {
        String sql = "SELECT * FROM users where username = ?";
        return jdbcTemplate.queryForObject(sql, new Object[]{username}, (rs, rowNum) -> {
            Users users = new Users();
            users.setId(Integer.valueOf(rs.getString("id")));
            users.setUsername(rs.getString("username"));
            users.setPassword(rs.getString(3));
            return users;
        });
    }
}
